#include "Result.h"
using namespace BWAPI;
using namespace std;

Result::Result(void)
{
	totalHitPoints = 0;
}

Result::Result(map<string, vector<BattleSimulator::UnitStats*>*>* data)
{
	totalHitPoints = 0;
	setResult(data);
}

Result::~Result(void)
{

}

// uses only totalHitPoints for 
void Result::setResult(map<string, vector<BattleSimulator::UnitStats*>*>* data)
{
	for(map<string, vector<BattleSimulator::UnitStats*>*>::iterator type 
		= data->begin(); type != data->end(); type++)
	{
		for(vector<BattleSimulator::UnitStats*>::iterator unit = 
			(*type).second->begin();unit != (*type).second->end();unit++)
		{
			if(!(*unit)->dead)
				totalHitPoints +=(*unit)->hp;
		}
	}

}

void Result::lost(){totalHitPoints *=-1;}

bool Result::isBetter(Result &rhs) const
{
	return(rhs.totalHitPoints > totalHitPoints);
}